<template>
    <div class="booking-table-list">
        <el-table
                ref="bookingTable"
                :data="tableData"
                :height="tableHeight"
                border
                style="width: 100%"
                :row-class-name="tableRowClassName"
                @selection-change="handleSelectionChange"
                :default-sort="defaultSort">
            <el-table-column
                    type="selection"
                    show-overflow-tooltip
                    width="50">
            </el-table-column>
            <el-table-column
                    prop="number"
                    label="编号"
                    width="95"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="JGName"
                    label="机构名称"
                    width="250"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="contact"
                    label="联系人"
                    width="125"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="bookingTime"
                    label="预约时间"
                    width="150"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="operator"
                    label="操作人"
                    width="125"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="bookingStatus"
                    label="预约状态"
                    width="125"
                    :filters="bookingStatusFilter"
                    :filter-method="filterBookingStatus"
                    filter-placement="bottom-end">
                <template slot-scope="scope">
                    <el-tag :type="bookingStatusType(scope.row.bookingStatus)" close-transition>
                        {{scope.row.bookingStatus}}
                    </el-tag>
                </template>
            </el-table-column>
            <el-table-column
                    prop="operateDate"
                    label="操作日期"
                    width="125"
                    sortable>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            @click="handleEdit(scope.$index, scope.row)">编辑
                    </el-button>
                    <el-button
                            size="mini"
                            type="danger"
                            @click="handleDelete(scope.$index, scope.row)">删除
                    </el-button>
                    <el-button size="mini" type="primary" @click="handleLook(scope.$index, scope.row)">查看</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    export default {
        name: "BookingTableList",
        props: {
            tableHeight: {
                required: false,
                type: String,
                default: () => {
                    return "550";
                }
            },
            defaultSort: {
                required: false,
                type: Object,
                default: () => {
                    return {prop: 'number', order: 'descending'};
                }
            }
        },
        computed: {
            bookingStatusFilter() {
                return [{text: '未联系', value: '未联系'}, {text: '未达目的', value: '未达目的'}, {text: '已完成', value: '已完成'}];
            },
        },
        data() {
            return {
                multipleSelection: [],
                tableData: [{
                    number: '10021',
                    JGName: '九江市科技情报所',
                    contact: '李英国',
                    bookingTime: '2016-08-04 10:30',
                    operator: '夏小芳',
                    bookingStatus: '已完成',
                    operateDate: '2019-11-12',
                }, {
                    number: '10021',
                    JGName: '九江市科技情报所',
                    contact: '李英国',
                    bookingTime: '2016-08-04 10:30',
                    operator: '夏小芳',
                    bookingStatus: '未联系',
                    operateDate: '2019-11-12',
                }, {
                    number: '10021',
                    JGName: '九江市科技情报所',
                    contact: '李英国',
                    bookingTime: '2016-08-04 10:30',
                    operator: '夏小芳',
                    bookingStatus: '已完成',
                    operateDate: '2019-11-12',
                }, {
                    number: '10021',
                    JGName: '九江市科技情报所',
                    contact: '李英国',
                    bookingTime: '2016-08-04 10:30',
                    operator: '夏小芳',
                    bookingStatus: '未联系',
                    operateDate: '2019-11-12',
                }, {
                    number: '10021',
                    JGName: '九江市科技情报所',
                    contact: '李英国',
                    bookingTime: '2016-08-04 10:30',
                    operator: '夏小芳',
                    bookingStatus: '已完成',
                    operateDate: '2019-11-12',
                }, {
                    number: '10021',
                    JGName: '九江市科技情报所',
                    contact: '李英国',
                    bookingTime: '2016-08-04 10:30',
                    operator: '夏小芳',
                    bookingStatus: '未联系',
                    operateDate: '2019-11-12',
                }, {
                    number: '10021',
                    JGName: '九江市科技情报所',
                    contact: '李英国',
                    bookingTime: '2016-08-04 10:30',
                    operator: '夏小芳',
                    bookingStatus: '未联系',
                    operateDate: '2019-11-12',
                }, {
                    number: '10021',
                    JGName: '九江市科技情报所',
                    contact: '李英国',
                    bookingTime: '2016-08-04 10:30',
                    operator: '夏小芳',
                    bookingStatus: '未达目的',
                    operateDate: '2019-11-12',
                }, {
                    number: '10021',
                    JGName: '九江市科技情报所',
                    contact: '李英国',
                    bookingTime: '2016-08-04 10:30',
                    operator: '夏小芳',
                    bookingStatus: '未联系',
                    operateDate: '2019-11-12',
                }, {
                    number: '10021',
                    JGName: '九江市科技情报所',
                    contact: '李英国',
                    bookingTime: '2016-08-04 10:30',
                    operator: '夏小芳',
                    bookingStatus: '已完成',
                    operateDate: '2019-11-12',
                }]
            }
        },
        methods: {
            bookingStatusType(bookingStatus) {
                switch (bookingStatus) {
                    case '已完成':
                        return 'success';
                    case '未达目的':
                        return 'warning';
                    case '未联系':
                        return 'danger';
                }
            },
            /**
             * 编辑
             * @param index
             * @param row
             */
            handleEdit(index, row) {
                console.log(index, row);
            },
            /**
             * 删除
             * @param index
             * @param row
             */
            handleDelete(index, row) {
                console.log(index, row);
            },
            /**
             * 查看
             * @param index
             * @param row
             */
            handleLook(index, row) {
                console.log(index, row);
            },
            /**
             * 预约状态过滤
             * @param value
             * @param row
             * @returns {boolean}
             */
            filterBookingStatus(value, row) {
                return row.status === value;
            },
            /**
             * 行背景色处理
             * @param row
             * @param rowIndex
             * @returns {string}
             */
            tableRowClassName({row, rowIndex}) {
                if (row.bookingStatus === '未达目的') {
                    return 'warning-row';
                } else if (row.bookingStatus === '已完成') {
                    return 'success-row';
                } else if (row.bookingStatus === '未联系') {
                    return 'danger-row'
                }
                return '';
            },
            /**
             * 选中行处理
             * @param val
             */
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        }
    }
</script>

<style lang="scss">
    .booking-table-list {

    }
</style>